package com.ruoyi.hqfinance.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.hqfinance.domain.HqSheetType;
import com.ruoyi.hqfinance.domain.UCodeMerchant;
import com.ruoyi.hqfinance.service.HqSheetTypeService;
import com.ruoyi.hqfinance.service.UCodeMerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hq/sheetType")
@Api(tags = "总部财务-面单类型")
public class HqSheetTypeController {
    @Autowired
    private HqSheetTypeService hqSheetTypeService;

    @ApiOperation("查全部")
    @GetMapping("/selectAll")
    public R selectAll() {
        List<HqSheetType> hqSheetTypes = hqSheetTypeService.selectAll();
        if (hqSheetTypes == null || hqSheetTypes.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(hqSheetTypes);
        }
    }

    @ApiOperation("添加")
    @PostMapping("/insert")
    public R insert(@RequestBody HqSheetType hqSheetType){
        Boolean isAdd = hqSheetTypeService.insert(hqSheetType);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public R update(@RequestBody  HqSheetType hqSheetType){
        Boolean isUpdate = hqSheetTypeService.update(hqSheetType);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public R delete(Integer id){
        Boolean isDelete = hqSheetTypeService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
}


